/**
 * 
 */
package com.module.osr.ui.stormbringer.charcreator.widgets;

import com.ahq.main.H1HighlightBorder;
import com.dalonedrau.jogl.engine.Action;
import com.dalonedrau.jogl.engine.GameApplet;
import com.dalonedrau.jogl.engine.InputEvent;
import com.dalonedrau.jogl.engine.Interactive;
import com.dalonedrau.jogl.opengl.ui.Button;
import com.dalonedrau.jogl.opengl.ui.GuiComponent;
import com.dalonedrau.jogl.opengl.ui.UIFactory;
import com.dalonedrau.jogl.opengl.ui.panel.LandscapePagePanel;
import com.dalonedrau.jogl.opengl.ui.panel.Panel;
import com.dalonedrau.jogl.opengl.ui.panel.PortraitPagePanel;
import com.module.osr.engine.OSRController;
import com.module.osr.stormbringer.bus.SBCharacter;
import com.module.stormbringer.globals.Globals;
import com.rpg.base.RPGConsts;

/**
 * @author Donald
 */
public final class GenderOptions extends LandscapePagePanel {
	/** the "Done" button. */
	private Button	btnFemale;
	/** the "Done" button. */
	private Button	btnMale;
	/** Creates a new instance of {@link GenderOptions}. */
	public GenderOptions() {
		super(Panel.LANDSCAPE_CENTER);
		super.setHorizontalAlignment(GuiComponent.TEXT_JUSTIFY);
		btnMale = UIFactory.getInstance().getStandardButton("Male");
		btnMale.setHighlightable(true);
		btnMale.setActive(true);
		btnMale.setHighlightBorder(new H1HighlightBorder());
		
		btnFemale = UIFactory.getInstance().getStandardButton("Female");
		btnFemale.setHighlightable(true);
		btnFemale.setActive(true);
		btnFemale.setHighlightBorder(new H1HighlightBorder());
		
		btnMale.addAction(new Action() {
			/**
			 * {@inheritDoc}
			 */
			@Override
			public void performAction() {
				btnMale.setActive(false);
				btnFemale.setActive(true);
				try {
					SBCharacter pc = 
						(SBCharacter) Interactive.getInstance().getIO(0);
					InputEvent.getInstance().addAction(
							pc, // object
							pc.getClass().getMethod(
									"setAverageSchmo", 
									new Class[] { Integer.TYPE }), 
							new Object[] { Globals.GENDER_MALE }
							);
					/*
					pc.setGender(Globals.GENDER_MALE);
					if (pc.getSkinTone() < 0) {
						pc.setSkinTone(RPGConsts.SKIN_01CELT);
						pc.setHeight(RPGConsts.HEIGHT_00AVERAGE);
						pc.setBaseBodyFrame(RPGConsts.BUILD_01MEDIUM);
						pc.setMuscle(RPGConsts.MUSCLE_00AVERAGE);
					}
					*/
				} catch (Exception ex) {
					JOGLErrorHandler.getInstance().fatalError(ex);
				}
			}
		});
		super.addChild(btnMale);
		super.addChild(UIFactory.getInstance().getSpacer(10, 1));
		btnFemale.addAction(new Action() {
			/**
			 * {@inheritDoc}
			 */
			@Override
			public void performAction() {
				btnFemale.setActive(false);
				btnMale.setActive(true);
				try {
					SBCharacter pc = 
						(SBCharacter) Interactive.getInstance().getIO(0);
					InputEvent.getInstance().addAction(
							pc, // object
							pc.getClass().getMethod(
									"setAverageSchmo", 
									new Class[] { Integer.TYPE }), 
							new Object[] { Globals.GENDER_FEMALE }
							);
					/*
					pc.setGender(Globals.GENDER_FEMALE);
					if (pc.getSkinTone() < 0) {
						pc.setSkinTone(RPGConsts.SKIN_01CELT);
						pc.setHeight(RPGConsts.HEIGHT_00AVERAGE);
						pc.setBaseBodyFrame(RPGConsts.BUILD_01MEDIUM);
						pc.setMuscle(RPGConsts.MUSCLE_00AVERAGE);
					}
					*/
				} catch (Exception ex) {
					JOGLErrorHandler.getInstance().fatalError(ex);
				}
			}
		});
		super.addChild(btnFemale);
	}
	/**
	 * Sets the gender assigned through the wizard.
	 * @param gender male or female
	 */
	public void setGender(final int gender) {
		if (gender == RPGConsts.GENDER_MALE) {
			btnMale.setActive(false);
			btnFemale.setActive(true);
		} else {
			btnFemale.setActive(false);
			btnMale.setActive(true);
		}
	}
}
